using System;

namespace IEVin.PropertyChangedNotificator.Helper
{
    class TypeCache<T>
    {
        // ReSharper disable once StaticMemberInGenericType
        private static Type type;

        public static Type GetOrCreate(Func<Type, Type> creator)
        {
            if(type != null)
            {
                return type;
            }

#pragma warning disable CA2002 // 不要锁定具有弱标识的对象
            lock (typeof(TypeCache<T>))
#pragma warning restore CA2002 // 不要锁定具有弱标识的对象
            {
                return type ??= creator(typeof(T));
            }
        }
    }
}
